#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <time.h>
#include  <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <malloc.h>

#define NAMELEN 256
#define MSGLEN 256
#define PORT 9741
#define SETTINGPORT 9740
#define BUFLEN 1024
#define SERVERIP "10.1.233.100"

#ifndef COMMONFORMATS_NEW_H_INCLUDED
#define COMMONFORMATS_NEW_H_INCLUDED
#define MAXMEMBER 100

typedef struct ClientRequest         //! Request from Clients to Server
{
    unsigned int requestType;
	char senderName[NAMELEN];
	char destName[NAMELEN];
	char senderPasswd[9];
	char sourceIP[16];
	char destIP[16];
	char nickName[NAMELEN];
	int state;
	char gender[50];
	unsigned int age;
	char branch[NAMELEN];
	char telephone[12];
	char birthdate[12];
	unsigned int profilepic;
	char msg[MSGLEN];

} clientRequest;
#endif // COMMONFORMATS_NEW_H_INCLUDED

typedef struct UserIP
{
        char Name[NAMELEN];
        char IPaddress[16];
}userIP;

typedef struct Userstate
{
        char Name[NAMELEN];
        int state;
}userstate;

typedef struct Chatmsg
{
        char Name[NAMELEN];
        char msg[1024];
}chatmsg;
chatmsg chat_msg[10];

typedef struct GPChatmsg
{
        char Name[NAMELEN];
        char msg[1024];
        char branch[30];
}gpchatmsg;
gpchatmsg gpchat_msg[10];

typedef struct Userwindow
{
        char Name[NAMELEN];
        int flag;
}userwindow;
userwindow user_window[100];

const gchar *Login_UsernameEntry_char;
const gchar *Login_PasswdEntry_char;

clientRequest myinformation;

int user_num;//所有用户人数
clientRequest userinfo[100];//所有用户的信息
pthread_t drawimage_t;//闪动头像的线程
int mydrawimage;
int ImageNo[36];



//Builder声明
GtkBuilder *Login_builder;
GtkBuilder *Register_builder;
GtkBuilder *Mainframe_builder;
GtkBuilder *Setting_builder;
GtkBuilder *Group_builder;
GtkBuilder *Buildgroup_builder;
GtkBuilder *Ptp_builder;
GtkBuilder *Psderror_builder;
GtkBuilder *Loginerror_builder;
GtkBuilder *Registersuccess_builder;
GtkBuilder *Registerfail_builder;
GtkBuilder *Servererror_builder;
GtkBuilder *Necinfo_builder;
GtkBuilder *Reregister_builder;

//window声明
GtkWidget *Login_Window;
GtkWidget *Mainframe_Window;
GtkWidget *Register_Window;
GtkWidget *Setting_Window;
GtkWidget *Group_Window;
GtkWidget *Buildgroup_Window;
GtkWidget *Ptp_Window;
GtkWidget *Psderror_Window;
GtkWidget *Loginerror_Window;
GtkWidget *Registersuccess_Window;
GtkWidget *Registerfail_Window;
GtkWidget *Servererror_Window;
GtkWidget *Necinfo_Window;
GtkWidget *Reregister_Window;

//控件声明
GtkWidget *Login_UsernameEntry;
GtkWidget *Login_PasswdEntry;
GtkWidget *Login_LoginButton;
GtkWidget *Login_QuitButton;
GtkWidget *Login_RegisterButton;
GtkWidget *Login_CheckButton;

GtkWidget *Register_UsernameEntry;
GtkWidget *Register_PasswdEntry;
GtkWidget *Register_PsdconfEntry;
GtkWidget *Register_AgeEntry;
GtkWidget *Register_GenderCombox;
GtkWidget *Register_BranchCombox;
GtkWidget *Register_TelephoneEntry;
GtkWidget *Register_NicknameEntry;
GtkWidget *Register_BirthEntry;
GtkWidget *Error_PsdLabel;
GtkWidget *Error_NecinfoLabel;
GtkWidget *Register_ConfirmButton;
GtkWidget *Register_CancelButton;

GtkWidget *Mainframe_SettingButton;

GtkWidget *Psderror_Button;

GtkWidget *Loginerror_Button;

GtkWidget *Registersuccess_Button;

GtkWidget *Registerfail_Button;

GtkWidget *Servererror_Button;
GtkWidget *Necinfo_Button;
GtkWidget *imgsltwindow;

GtkWidget *Reregister_Button;

  GtkWidget *scrolledwindow1;
  GtkWidget *btn1[210];
  GtkWidget *image1[210];
  GtkWidget *label1[210];
  //GtkWidget *layout1;
  GtkWidget *fixed;
  GtkWidget *viewport1;

//回调函数
clientRequest Get_client_request(char* buffer);
void on_Register_CancelButton_clicked();
void on_Register_ConfirmButton_clicked();

void on_Mainframe_SettingButton_clicked();

void on_Psderror_Button_clicked();

void on_Servererror_Button_clicked();

void on_Loginerror_Button_clicked();

void on_Registerfail_Button_clicked();

void on_Registersuccess_Button_clicked();

void on_Reregister_Button_clicked();

void on_Login_LoginButton_clicked();
void on_Login_QuitButton_clicked();
void on_Login_RegisterButton_clicked();
void on_Login_Window_destroy_event();
void show_conversation_window();

void on_Necinfo_Button_clicked();

void *Mainframe_Listenthread(void *arg);              //主窗口监听线程

void on_MygroupBtn_clicked(GtkObject *object,gpointer user_data);

void  show_pesornal_info (GtkButton *button, clientRequest *user_data);

//void *draw_msgreceived_image(clientRequest * user_data);//消息窗口没打开时闪动头像

